# -*- coding: utf-8 -*-
from datetime import timedelta
from utils.operators.cluster_for_spark_sql_hook_test_for_airflow_bug_operator import SparkSqlOperator

#from jms.dwd.tms.dwd_tmsnew_shipment_union_base_dt import jms_dwd__dwd_tmsnew_shipment_union_base_dt
#from jms.dwd.tms.dwd_tmsnew_shipment_stop_union_base_dt import jms_dwd__dwd_tmsnew_shipment_stop_union_base_dt
#from jms.dwd.tab.dwd_tab_barscan_loading_base_dt import jms_dwd__dwd_tab_barscan_loading_base_dt
#from jms.dwd.tab.dwd_tab_barscan_unloading_base_dt import jms_dwd__dwd_tab_barscan_unloading_base_dt
#from jms.time_sensor.time_after_04_00 import time_after_04_00

jms_dm__dm_shipment_stop_billcode_detail_dt  = SparkSqlOperator(
    task_id='jms_dm__dm_shipment_stop_billcode_detail_dt',
    email=['guoruiling@jtexpress.com','yl_bigdata@yl-scm.com'],
    name='jms_dm__dm_shipment_stop_billcode_detail_dt_{{ execution_date | date_add(1) | cst_ds }}',
    sql='jms_route_test/dm/dm_shipment_stop_billcode_detail_dt/execute.hql',
    pool_slots=1,
    retries=1,
    driver_memory='4G',
    executor_memory='8G',
    executor_cores=4,
    num_executors=20,
    yarn_queue='pro',
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
          'spark.dynamicAllocation.maxExecutors': 50,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 60,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
          'spark.executor.memoryOverhead': '2G',  # 堆外内存
          'spark.default.parallelism': 500,
          'spark.sql.shuffle.partitions': 500
          },

    #excel平均时长:8分54秒
    execution_timeout = timedelta(minutes=30),
    hiveconf={'hive.exec.dynamic.partition': 'true',  # 动态分区
          'hive.exec.dynamic.partition.mode': 'nonstrict',
          'hive.exec.max.dynamic.partitions': 180,  # -表示一个动态分区语句可以创建的最大动态分区个数，超出报错
          'hive.exec.max.dynamic.partitions.pernode': 180,  # 默认100，一般可以设置大一点，比如1000。表示每个maper或reducer可以允许创建的最大动态分区个数，默认是100，超出则会报错。
          },
)

jms_dm__dm_shipment_stop_billcode_detail_dt  << [
    #jms_dwd__dwd_tmsnew_shipment_union_base_dt,
    #jms_dwd__dwd_tmsnew_shipment_stop_union_base_dt,
    #jms_dwd__dwd_tab_barscan_loading_base_dt,
    #jms_dwd__dwd_tab_barscan_unloading_base_dt,
    #time_after_04_00
]
 